package logic

import (
	"context"
	"renting-demo/user_srv/userclient"
	"strconv"

	"renting-demo/api/internal/svc"
	"renting-demo/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserInfoLogic {
	return &UserInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserInfoLogic) UserInfo(req *types.UserInfoRequest) (resp *types.Data, err error) {
	// todo: add your logic here and delete this line
	res, err := l.svcCtx.UserServer.GetUserInfo(context.Background(), &userclient.GetUserInfoRequest{
		UserID: int64(req.UserId),
	})
	if err != nil {
		return &types.Data{
			Code:    500,
			Message: err.Error(),
		}, nil
	}
	return &types.Data{
		Code:    0,
		Message: "查询成功",
		Data:    map[string]string{"userID": strconv.FormatInt(res.UserID, 10), "realName": res.RealName, "identityCard": res.IdentityCard},
	}, nil
}
